import {
  getToken,
  setToken,
  removeToken
} from '@/utils/auth'
import {
  queryList,
  userQueryList
} from '@/api/subsys/userRole'

const userRole = {
  state: {
    token: getToken(),
    name: '',
    avatar: '',
    roles: []
  },

  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_NAME: (state, name) => {
      state.name = name
    },
    SET_AVATAR: (state, avatar) => {
      state.avatar = avatar
    },
    SET_ROLES: (state, roles) => {
      state.roles = roles
    }
  },

  actions: {
    // 查询全部
    UserRoleUserQueryList({
      commit
    }, datas) {
      return new Promise((resolve, reject) => {
        queryList(datas).then(response => {
          // const data = response.data
          // setToken(data.token)
          // commit('SET_TOKEN', data.token)
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  },

  // 查询所有用户
  UserQueryList3({
    commit
  }, datas) {
    return new Promise((resolve, reject) => {
      userQueryList(datas)
        .then(response => {
          // const data = response.data
          // setToken(data.token)
          // commit('SET_TOKEN', data.token)
          resolve(response)
        })
        .catch(error => {
          reject(error)
        })
    })
  }

}

export default userRole
